package com.wugui.datax.job.mapper.base;

import com.github.CCweixiao.HBaseAdminTemplate;
import com.github.CCweixiao.HBaseSqlTemplate;
import com.github.CCweixiao.HBaseTemplate;
import com.wugui.datax.job.entity.JobDatasource;
import com.wugui.datax.job.service.JobDatasourceService;
import com.wugui.datax.job.util.JdbcConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author luofei
 * @date 2021/6/25 16:55
 */
@Component
public class HbaseMapper {
    /**
     * 数据读写API
     */
    private HBaseTemplate hBaseTemplate;
    /**
     * 管理员API
     */
    private HBaseAdminTemplate hBaseAdminTemplate;
    /**
     * HQL操作API
     */
    private HBaseSqlTemplate hBaseSqlTemplate;
    /**
     * 数据源查询服务
     */
    @Autowired
    private JobDatasourceService jobDatasourceService;

    public HBaseTemplate hBaseTemplate(){
        if(this.hBaseTemplate==null){
            JobDatasource jobDatasource = jobDatasourceService.getDatasource(JdbcConstants.DATASOURCE_DW_ID);
            String host=jobDatasource.getZkAdress().split(":")[0];
            String port=jobDatasource.getZkAdress().split(":")[1];
            hBaseTemplate = new HBaseTemplate(host, port);
        }
        return this.hBaseTemplate;
    }
    public HBaseAdminTemplate hBaseAdminTemplate(){
        if(this.hBaseAdminTemplate==null){
            JobDatasource jobDatasource = jobDatasourceService.getDatasource(JdbcConstants.DATASOURCE_DW_ID);
            String host=jobDatasource.getZkAdress().split(":")[0];
            String port=jobDatasource.getZkAdress().split(":")[1];
            hBaseAdminTemplate = new HBaseAdminTemplate(host, port);
        }
        return this.hBaseAdminTemplate;
    }
    public HBaseSqlTemplate hBaseSqlTemplate(){
        if(this.hBaseSqlTemplate==null){
            JobDatasource jobDatasource = jobDatasourceService.getDatasource(JdbcConstants.DATASOURCE_DW_ID);
            String host=jobDatasource.getZkAdress().split(":")[0];
            String port=jobDatasource.getZkAdress().split(":")[1];
            hBaseSqlTemplate = new HBaseSqlTemplate(host, port);
        }
        return this.hBaseSqlTemplate;
    }


}
